/**
 * Belongs to WEF
 */

// 页面编辑数据
var inputsDatacheckedForm={};
var textareasDatacheckedForm={};
var selectsDatacheckedForm={};
var status;
// 记录下表单中的原始值
function initFileds(formId) {
	
	var inputs = $("input",$("#"+formId));
	var textareas = $("textarea",$("#"+formId));
	var selects = $("select",$("#"+formId));
	inputsDatacheckedForm[formId]={};
	textareasDatacheckedForm[formId]={};
	selectsDatacheckedForm[formId]={};
	inputsDatacheckedForm[formId].values= new Array(inputs.length);
	for (var i = 0; i < inputs.length; i++) {
		if(inputs[i].type == "checkbox"){
			inputsDatacheckedForm[formId].values[i] = inputs[i].checked;
		}
		else if (inputs[i].type == "radio") {
			inputsDatacheckedForm[formId].values[i] = inputs[i].checked;
		}
		else if(inputs[i].type == "text"){
			inputsDatacheckedForm[formId].values[i] = inputs[i].value;
		}
	}
	textareasDatacheckedForm[formId].values = new Array(textareas.length);
	for (var i = 0; i < textareas.length; i++) {
		textareasDatacheckedForm[formId].values[i] = textareas[i].value;
	}
	selectsDatacheckedForm[formId].values = new Array(selects.length);
	for (var i = 0; i < selects.length; i++) {
		selectsDatacheckedForm[formId].values[i] = selects[i].value;
	}
}
/*
 * 判断表单中值是否被修改了
 */
function checkModification(formId) {
	var inputs = $("input",$("#"+formId));
	var textareas = $("textarea",$("#"+formId));
	var selects = $("select",$("#"+formId));
	var hasBeenChanged = false;
	for (var i = 0; i < inputs.length; i++) {
		if (inputs[i].type == "radio" && inputsDatacheckedForm[formId].values[i] != undefined
				&& (inputs[i].checked != inputsDatacheckedForm[formId].values[i])) {
			hasBeenChanged = true;
			break;
		}
		else if (inputs[i].type == "checkbox" && inputsDatacheckedForm[formId].values[i] != undefined
				&& (inputs[i].checked != inputsDatacheckedForm[formId].values[i])) {
			hasBeenChanged = true;
			break;
		}
		else if(inputs[i].type == "text" && inputsDatacheckedForm[formId].values[i] != undefined
				&& (inputs[i].value != inputsDatacheckedForm[formId].values[i])){
			hasBeenChanged = true;
			break;	
		}
	}
	if(!hasBeenChanged){
		for (var i = 0; i < textareas.length; i++) {
			if (textareasDatacheckedForm[formId].values[i] != undefined && textareasDatacheckedForm[formId].values[i] != textareas[i].value) {
				hasBeenChanged = true;
				//textareasDatacheckedForm[formId].values[i] = textareas[i].value;
				break;
			}
		}
	}
	if(!hasBeenChanged){
		for (var i = 0; i < selects.length; i++) {
			if (selectsDatacheckedForm[formId].values[i] != undefined && selectsDatacheckedForm[formId].values[i] != selects[i].value) {
				hasBeenChanged = true;
				break;
			}
		}
	}
	return hasBeenChanged;
}

function saveFormData(formId){
	status=true;
	$('#'+formId).submit();
}
